#pragma once

#include <gofcl_timer_ctl0.h>

typedef enum {
	TIMER_CTL0_DIRECTION_UP = 0,
	TIMER_CTL0_DIRECTION_DOWN = 1,
} timer_ctl0_direction_e;

typedef enum {
	TIMER_CTL0_COUNTER_ALIGN_EDGE = 0,
	TIMER_CTL0_COUNTER_ALIGN_CENTER_DOWN_1 = 1,
	TIMER_CTL0_COUNTER_ALIGN_CENTER_UP_1 = 2,
	TIMER_CTL0_COUNTER_ALIGN_CENTER_UP_DOWN_1 = 3,
} timer_ctl0_counter_align_e;

typedef enum {
	TIMER_CTL0_CLOCK_NO_DIV = 0,
	TIMER_CTL0_CLOCK_DIV_2 = 1,
	TIMER_CTL0_CLOCK_DIV_4 = 2,
} timer_ctl0_clock_prescale_e;

typedef struct {
	u16_s counter_en : 1;
	u16_s update_dis : 1;
	u16_s update_source : 1;
	u16_s single_pulse_mode : 1;
	__attribute__((packed)) timer_ctl0_direction_e direction : 1;
	__attribute__((packed)) timer_ctl0_counter_align_e counter_align : 2;
	u16_s auto_reload_shadow_en : 1;
	__attribute__((packed)) timer_ctl0_clock_prescale_e clock_prescale : 2;
	u16_s : 6;
} timer_ctl0_expl_s;

_Static_assert(sizeof(timer_ctl0_expl_s) == 2,
	       "Struct timer_ctl0_expl_s defined error!");

static inline void timer_setup_0(timer_qe timer_q, timer_ctl0_expl_s ctl0) {
	union {
		timer_ctl0_expl_s e;
		timer_ctl0_s c;
	} cu = {
		.e = ctl0,
	};
	timer_wreg_ctl0_s(timer_q, cu.c);
}
